//
//  NSObject+MCLotteryIDHelper.m
//  TLYL
//
//  Created by miaocai on 2017/6/9.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCLotteryID.h"

static NSDictionary *_instanceCZ;
static NSDictionary *_instanceWF;
static NSDictionary *_instanceCZHelper;

@implementation MCLotteryID : NSObject
    
    /*
     *从jsondata中获取CZ对象
     */
+ (NSDictionary *)getLotteryCZJsonDataInstance{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{

        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"LotteryJSON_CZ" ofType:@"json"];
        NSData *dataJson = [NSData dataWithContentsOfFile:filePath];
        _instanceCZ = [NSJSONSerialization JSONObjectWithData:dataJson options:NSJSONReadingAllowFragments error:nil];

    });
    return _instanceCZ;
}

//+ (NSString *)getLotteryFullIDByName:(NSString *)FullName{
//    
//}
    /*
     *从jsondata中获取WF对象
     */
+ (NSDictionary *)getLotteryWFJsonDataInstance{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"LotteryJSON_WF" ofType:@"json"];
        NSData *dataJson = [NSData dataWithContentsOfFile:filePath];
        _instanceWF = [NSJSONSerialization JSONObjectWithData:dataJson options:NSJSONReadingAllowFragments error:nil];
        
    });
    return _instanceWF;
}
    
    
    /*
     *从jsondata中获取CZHelper对象
     */
+ (NSDictionary *)getLotteryCZHelperJsonDataInstance{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"LotteryJSON_CZHelper" ofType:@"json"];
        NSData *dataJson = [NSData dataWithContentsOfFile:filePath];
        _instanceCZHelper = [NSJSONSerialization JSONObjectWithData:dataJson options:NSJSONReadingAllowFragments error:nil];
        
    });
    return _instanceCZHelper;
}
    
    
    /*
     *根据彩票id找彩票type
     */
+ (NSString *)getLotteryCategoriesTypeNameByID:(NSString *)categoriesID{
    
    NSDictionary *dic = [self getLotteryCZHelperJsonDataInstance];
    
    return dic[categoriesID][@"type"];
}
    
    /*
     *根据彩票id找彩票种类名称
     */
+ (NSString *)getLotteryCategoriesNameByID:(NSString *)categoriesID{
    
   NSDictionary *dic = [self getLotteryCZHelperJsonDataInstance];
    
    return dic[categoriesID][@"name"];
}
    
    /*
     *根据彩票id找彩票玩法名称
     */
+ (NSString *)getLotteryWFNameByID:(NSString *)categoriesID{
    
    NSDictionary *dic = [self getLotteryWFJsonDataInstance];
    
    return dic[categoriesID][@"name"];
}
    /*
     *根据彩票type找彩票玩法列表
     */
+ (NSDictionary *)getLotteryWFType:(NSString *)categoriesType{
    
    NSDictionary *dic = [self getLotteryWFJsonDataInstance];
    
    return dic[categoriesType];
}
    /*
     *根据彩票id找到彩票的名称玩法
     */
+ (NSString *)getLotteryFullNameByID:(NSString *)FullID{
    NSString *lcID = @"";
    NSString *wcID = @"";
    if (FullID.length == 3) {
        lcID = [FullID substringToIndex:1];
        wcID = [FullID substringWithRange:NSMakeRange(1, FullID.length - 1)];
    } else {
        lcID = [FullID substringToIndex:2];
        wcID = [FullID substringWithRange:NSMakeRange(2, FullID.length - 2)];
    }
    
    NSString *lotteryName = [self getLotteryCategoriesNameByID:lcID];
    NSString *typeName = [self getLotteryCategoriesTypeNameByID:lcID];
    NSDictionary *dic = [self getLotteryWFType:typeName];
    NSArray *palyMethodArray = dic[@"playMethod"];
    NSString *name = @"";
    NSString *typeWFName = @"";
    for (NSDictionary *dic in palyMethodArray) {
        if (dic[@"methodId"] == wcID) {
           name = dic[@"name"];
           typeWFName = dic[@"typeName"];
            
        }
    }
    
    NSString *fullName = [NSString stringWithFormat:@"%@%@%@",lotteryName,typeWFName,name];
    return fullName;
}
   
    

    
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    
    if (jsonString == nil) {return nil;}
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
    
}
    

@end
